package com.dormitory.dormitorymanagement.mapper;


import com.dormitory.dormitorymanagement.pojo.*;
import com.dormitory.dormitorymanagement.pojo.vo.RepliesVo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface StudentsMapper {
    @Select("select * from dormitory.students where student_id = #{username}")
    Students findByStudentId(String username);


    @Insert("insert into dormitory.dorm_repair(student_id, location, content, repair_status, create_time) values (#{studentId},#{location},#{content},#{repairStatus},#{createTime})" )
    void insertImpair(DormRepair dormRepair);


    List<Students> findByStudentIds(List<String> studentIds);


    @Select("select * from dormitory.students")
    List<Students> getStudentsAll();


    @Select("select * from dormitory.notice where building_name = #{dormBuilding} order by create_time desc limit #{pageSize}")
    List<Notice> getLatestNotice(String dormBuilding, Integer pageSize);


    @Select("select * from dormitory.notice where id = #{noticeId}")
    Notice getNoticeDetail(Integer noticeId);



    /**
     *  获取班级公告
     * @param className
     * @param pageSize
     * @return
     */
    @Select( "select * from dormitory.class_notice where student_class = #{className} order by create_time desc limit #{pageSize}")
    List<ClassNotice> getLatestClassNotice(String className, Integer pageSize);




    /**
     * 获取班级公告详情
     * @param id
     * @return
     */
    @Select( "select * from dormitory.class_notice where id = #{id}")
    ClassNotice getClassNoticeDetail(Integer id);


    /**
     *  获取班级领导
     * @param className
     * @return
     */
    @Select( "select * from dormitory.students where class_name = #{className} and role != '学生'")
    List<Students> getClassLeader(String className);


    /***
     *  获取宿舍管理员
     * @param dormBuilding
     * @return
     */
    @Select( "select * from dormitory.dormitory_admin where building_responsible = #{dormBuilding}")
    List<DormitoryAdmin> getDormAdmin(String dormBuilding);


    /**
     *  评价
     * @param evaluations
     */
    @Insert( "insert into dormitory.student_evaluations(student_id, target_id, student_class, target_position, target_role, content, score, attitude, communication, ability, status,create_time) values (#{studentId},#{targetId},#{studentClass},#{targetPosition},#{targetRole},#{content},#{score},#{attitude},#{communication},#{ability},#{status},#{createTime})")
    void submit(StudentEvaluations evaluations);


    /**
     *
     * @param targetId
     * @param targetType
     * @return
     */

    /**
     * 根据学生id和评价对象类型获取评价
     * @param targetId
     * @param targetType
     * @return
     */
     @Select( "select * from dormitory.student_evaluations where target_id = #{targetId} and target_role = #{targetType}")
    StudentEvaluations getStudentEvaluations(String targetId, String targetType);


    /**
     *  提交帖子
     * @param posts
     */
     @Insert( "insert into dormitory.posts(student_id, title, content, student_class, create_time,author) values (#{studentId},#{title},#{content},#{studentClass},#{createTime},#{author})")
    void postsSubmit(Posts posts);

    /**
     * 获取帖子列表
     * @param className
     * @return
     */
     @Select( "select * from dormitory.posts where student_class = #{className} order by create_time desc")
    List<Posts> getPostsList(String className);

    /**
     *  获取帖子评论
     * @param id
     * @return
     */
    @Select( "select * from dormitory.comments where post_id = #{id} order by create_time desc")
    List<Comments> getComments(Integer id);


    /**
     *  获取帖子回复
     * @param id
     * @return
     */
    @Select( "select * from dormitory.replies where comment_id = #{id} order by create_time desc")
    List<RepliesVo> getReplies(Integer id);


    /**
     * 添加评论
     * @param comments
     */

    @Insert(  "insert into dormitory.comments(student_id, content, post_id, create_time, author) values (#{studentId},#{content},#{postId},#{createTime},#{author})")
    void commentSubmit(Comments comments);


    /**
     * 添加回复
     * @param replies
     */
    @Insert( "insert into dormitory.replies(student_id, content, comment_id, create_time, author) values (#{studentId},#{content},#{commentId},#{createTime},#{author})")
    void replySubmit(Replies replies);

    /**
     * 获取学生评价
     * @param studentId
     * @return
     */
    @Select(  "select * from dormitory.student_evaluations where student_id = #{studentId} order by create_time desc")
    List<StudentEvaluations> getStudentMyEvaluations(String studentId);


    @Insert( "insert into dormitory.students(student_id, name, dorm_building, dorm_room, username, password, role, create_time, update_time) values (#{studentId},#{name},#{dormBuilding},#{dormRoom},#{username},#{password},#{role},#{createTime},#{updateTime})")
    void insert(Students students);

    @Insert( "insert into dormitory.students(student_id, name, class_name, username, password, role, create_time, update_time) values (#{studentId},#{name},#{className},#{username},#{password},#{role},#{createTime},#{updateTime})")
    void insertClassLeader(Students students);
}
